//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include"logIn.h"
#include "selection.h"
#include "camp.h"
#include"Entrance11.h";
#include <windows.h>

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TselectionForm *selectionForm;
//---------------------------------------------------------------------------
__fastcall TselectionForm::TselectionForm(TComponent* Owner)
	: TForm(Owner)
{

}
//---------------------------------------------------------------------------

void __fastcall TselectionForm::btnShopClick(TObject *Sender)
{
	/* Instead of copying each project in this one, program the selection app
	 * to act like an actual loader and use the createprocess method to load
	 * the application.
	 * Source: http://msdn.microsoft.com/en-us/library/ms682512(VS.85).aspx
	 */

	// Set some variabes.
	char appPath[] = "Shop.exe"; 	// Path of the file.
	STARTUPINFO si = {0};
	PROCESS_INFORMATION pi = {0};

	// Start the child process.
	if (!CreateProcess(NULL,(appPath), NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi))
	{
		ShowMessage(AnsiString(appPath)+" was not found.");  // In case the file was not found.
	}
	else
	{
		// Hide the selection form.
		selectionForm->Visible = false;

		// Wait until child process exits.
		WaitForSingleObject(pi.hProcess, INFINITE);

		// Close process and thread handles.
		CloseHandle(pi.hProcess);
		CloseHandle(pi.hThread);

		// Show the selection form.
		selectionForm->Visible = true;
	}
}
//---------------------------------------------------------------------------
void __fastcall TselectionForm::Button5Click(TObject *Sender)
{
 logInForm->Visible=true;
 this->Visible=false;
}
//---------------------------------------------------------------------------
void __fastcall TselectionForm::FormClose(TObject *Sender, TCloseAction &Action)
{
 logInForm->Close();
}

//---------------------------------------------------------------------------

void __fastcall TselectionForm::Button3Click(TObject *Sender)
{
  this->Visible=false;
  campForm->Visible=true;
}
//---------------------------------------------------------------------------

void __fastcall TselectionForm::Button1Click(TObject *Sender)
{
  this->Visible=false;
  entranceForm->Visible=true;
}
//---------------------------------------------------------------------------

void __fastcall TselectionForm::btnLoanClick(TObject *Sender)
{
	/* Instead of copying each project in this one, program the selection app
	 * to act like an actual loader and use the createprocess method to load
	 * the application.
	 * Source: http://msdn.microsoft.com/en-us/library/ms682512(VS.85).aspx
	 */

	// Set some variabes.
	char appPath[] = "Loan.exe"; 	// Path of the file.
	STARTUPINFO si = {0};
	PROCESS_INFORMATION pi = {0};

	// Start the child process.
	if (!CreateProcess(NULL,(appPath), NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi))
	{
		ShowMessage(AnsiString(appPath)+" was not found.");  // In case the file was not found.
	}
	else
	{
		// Hide the selection form.
		selectionForm->Visible = false;

		// Wait until child process exits.
		WaitForSingleObject(pi.hProcess, INFINITE);

		// Close process and thread handles.
		CloseHandle(pi.hProcess);
		CloseHandle(pi.hThread);

		// Show the selection form.
		selectionForm->Visible = true;
    }
}
//---------------------------------------------------------------------------


